package com.heima.controller;


import com.heima.common.PageResult;
import com.heima.pojo.Partner;
import com.heima.pojo.dto.PageQueryDTO;
import com.heima.service.PartnerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/api/user-service/partner")
public class PartnerController {

    @Autowired
    private PartnerService partnerService;

    @PostMapping
    public Boolean save(@RequestBody Partner partner){
        log.info("新增合作商：{}",partner);
        return partnerService.save(partner);
    }

    @GetMapping("/search")
    public PageResult query(PageQueryDTO dto){
        log.info("合作商搜索：{}",dto);
        return partnerService.query(dto);
    }

    @GetMapping("/{id}")
    public Partner findById(@PathVariable Integer id){
        log.info("获取合作商详情：{}",id);
        return partnerService.findById(id);
    }

    @PutMapping("/{id}")
    public Boolean update(@PathVariable Integer id,@RequestBody Partner partner){
        log.info("修改合作商：{}",id,partner);
        return partnerService.update(id,partner);
    }

    @DeleteMapping("/{id}")
    public Boolean delete(@PathVariable Integer id){
        log.info("删除合作商：{}",id);
        return partnerService.delete(id);
    }


    @GetMapping("/count")
    public Integer partnerCount(){
        log.info("合作商数量：");
        return partnerService.partnerCount();
    }

    @PutMapping("/resetPwd/{id}")
    public Boolean resetPwd(@PathVariable Integer id){
        log.info("重置密码：{}",id);
        return partnerService.resetPwd(id);
    }
}
